package com.pandora.loan.home.mongo.service.impl;

import com.pandora.loan.common.util.Constants;
import com.pandora.loan.common.util.VerifyUtil;
import com.pandora.loan.home.dto.request.NewsRequest;
import com.pandora.loan.home.dto.response.LoanResponseNextInt;
import com.pandora.loan.home.mongo.dao.MongoActivityDao;
import com.pandora.loan.home.mongo.entity.MongoActivity;
import com.pandora.loan.home.mongo.service.MongoActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author developer
 */
@Service
public class MongoActivityServiceImpl implements MongoActivityService {

    @Autowired
    private MongoActivityDao mongoActivityDao;

    @Override
    public List<MongoActivity> queryByLength(int len) {
        return mongoActivityDao.selectByLength(len);
    }

    @Override
    public LoanResponseNextInt doGetActivities(NewsRequest req) {
        String nextId = req.getNextId();
        int length = 11;
        if(req.getLength() != null){
            length = Integer.parseInt(req.getLength());
        }
        List<MongoActivity> mongoActivities = queryByLength(length);

        return new LoanResponseNextInt(Constants.RETURN_TYPE_ACTIVITY,
                mongoActivities,
                VerifyUtil.isEmpty(nextId)?0:Integer.parseInt(nextId));
    }
}
